package org.yaac.shared.crud;

import java.io.Serializable;
import java.util.LinkedList;
import java.util.List;

/**
 * @author Max Zhu (thebbsky@gmail.com)
 *
 */
//TODO : meta property is not actually used in UI, deprecate this class?
public class MetaKind implements Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	
	private String kindName;
	
	private List<MetaProperty> properties;

	/**
	 * used by GWT
	 */
	@SuppressWarnings("unused")
	private MetaKind() {}
	
	/**
	 * @param kindName
	 */
	public MetaKind(String kindName) {
		super();
		this.kindName = kindName;
		this.properties = new LinkedList<MetaProperty>();
	}

	public void addProperty(String propertyName, List<String> representation) {
		this.properties.add(new MetaProperty(propertyName, representation));
	}
	
	public String getKindName() {
		return kindName;
	}

	public List<MetaProperty> getProperties() {
		return properties;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((kindName == null) ? 0 : kindName.hashCode());
		result = prime * result + ((properties == null) ? 0 : properties.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		MetaKind other = (MetaKind) obj;
		if (kindName == null) {
			if (other.kindName != null)
				return false;
		} else if (!kindName.equals(other.kindName))
			return false;
		if (properties == null) {
			if (other.properties != null)
				return false;
		} else if (!properties.equals(other.properties))
			return false;
		return true;
	}

	@Override
	public String toString() {
		return "Kind [kindName=" + kindName + ", properties=" + properties + "]";
	}
}